php - error: Database not selected -
i'm stuck issue: no database selected. roll on same problems posted here, after hours of reading can't figure out why database not selected. created database job
, table job
. run script wamp server. sorry "everyday question." please help!
<?php // load smarty library require('c:/wamp/www/smarty-3.1.21/libs/smarty.class.php'); $servername = "localhost"; $dbname = "job"; // create connection $conn = mysqli_connect($servername, $dbname); // check connection if (!$conn) { die("connection failed: " . mysqli_connect_error()); } $smarty = new smarty; $smarty->settemplatedir('c:\wamp\www\app\templates'); $smarty->setcompiledir('c:\wamp\www\app\templates_c'); $smarty->setconfigdir('c:\wamp\www\app\configs'); $smarty->setcachedir('c:\wamp\www\app\cache'); $rows = array(); $sql = "select * job"; $result = mysqli_query($conn, $sql); if (!$result) { echo 'mysql error: ' . mysqli_error($conn); exit; } while ($row = mysqli_fetch_assoc($result)) { $rows[] = $row; } $smarty->assign('output', $rows); $smarty->display('result.tpl'); mysqli_close($conn); ?>
those aren't right parameters mysqli_connect
. have pass host, username, password, , database name. passing host , database name, not connecting correctly.
Comments
Post a Comment