PHP - Mysql

php MySQLi

How can we work with database?

$dbconx = @mysql_connect(IPAddress, username, password);

if (! @mysql_select_db("jokes")) {
    echo "Unable to locate the jokes database.";

mysql_query($query, $dbconx);

while ($row = mysql_fetch_array($result)) {
    echo $row['JokeText'];

In the above code, the @ symbol infront of mysql_connect tell it to fail silently if it is not able to connect to the database, and in that case, the variable $dbconx has the value of false, and we can use it to determine if the connection was successful or not.

How can we check if there was an error?

$error_str = mysql_error();

How can we determine the number of affected rows?

For DELETE, INSERT, and UPDATE queries, MySQL also keep track of the number of rows affected:

$affected_rows = mysql_affected_rows();
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License