php - error on every sql query with mysqli -
i created new empty php file simple function mysqli query, this:
$dab = new mysqli($dbhost,$dbuser,$dbpassword,$dbdbname); function dbq($sql) { global $dab; $wynik= $dab->query($sql); if (!$wynik) { printf("errormessage: %s\n", $dab->error); } return $wynik; } dbq('set character set utf8'); dbq('set collation_connection = utf8_general_ci');
on every query i'm getting blank errormessage , don't know cause here.
script connecting database without errors. when performed looped query, recieved blank errormessage each repeat.
- you ought set proper php error reporting in order see php errors
- you have verify connect errors.
- you shouldn't echo errors out unconditionally.
- oh, , have set charset using right method
so, code be
error_reporting(e_all); ini_set('display_errors',1); $dab = new mysqli($dbhost,$dbuser,$dbpassword,$dbdbname); if ( !$dab ) { throw new exception(mysqli_connect_error()); } if (!$dab->set_charset('utf8')) { throw new exception($dab->error); } function dbq($sql) { global $dab; $wynik= $dab->query($sql); if (!$wynik) { throw new exception($dab->error); } return $wynik; }
Comments
Post a Comment