Dreamweaver Code Snippets - Mysqli New
👤 By dd | 📆
use this in dbx
if (!$mysqli = new mysqli($Cfg['SiteHostname'], $Cfg['SiteHostUser'], $Cfg['SiteHostPass'], $Cfg['SiteHostDb'])) {
if ($Debug) {
echo '<brSQL ERROR <br>' . __FILE__ . ' ---- LINE: ' . __LINE__ . '<br><span style="color:red">ERROR= ' . mysqli_connect_error() . '</span><hr><pre>';
print_r($Cfg);
echo '</pre>';
exit;
} else {
die('Fatal Error #6 LINE:' . __LINE__);
}
}
Single Query:
$sql="SELECT * FROM scripts WHERE secret='xyz'";
if ($result = $mysqli->query($sql)) {
$obj = $result->fetch_object();
echo '<PRE>LINE '.__LINE__.' - ';print_r($obj);echo '</pre>';
}
Multiple query
$sql="SELECT * FROM scripts";
if ($result = $mysqli->query($sql)) {
while($obj = $result->fetch_object()){
echo '<PRE>LINE '.__LINE__.' - ';print_r($obj);echo '</pre>';
}
}