Why DB UPDATE is simpler than SELECT?

Codes here !

Moderators: macek, egami, gesf

Post Reply
seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Why DB UPDATE is simpler than SELECT?

Post by seandisanti » Wed Apr 09, 2014 11:28 pm

you could just do:

Code: Select all

$rs=$db->query("SELECT cn FROM CNT",PDO::FETCH_ASSOC); //so you can reference results by field name
print_r($rs->fetch()); // to output array of associative values.
 
but the thing is that you want to add in error checking so that you can respond to errors and results that have no rows.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Why DB UPDATE is simpler than SELECT?

Post by seandisanti » Wed Apr 09, 2014 11:29 pm

also, to find out the number of rows returned, you can just echo $rs->rowCount() if the query was successful.

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Re: Why DB UPDATE is simpler than SELECT?

Post by seandisanti » Thu Apr 10, 2014 8:12 am

the FETCH_ASSOC dictates that the result of fetch() will be an associative array. If you want to access a single element of the array, it would be like:

Code: Select all

$rs=$db->query("SELECT cn FROM CNT",PDO::FETCH_ASSOC);
$row = $rs->fetch();
echo $row['cn'];
 

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests