小编Nik*_*lay的帖子

错误:未选择数据库

我遇到了这个问题:没有选择数据库.我翻过这里发布的相同问题,但经过几个小时的阅读后,我无法弄清楚为什么没有选择数据库.我创建了一个数据库job和一个表job.我用WAMP服务器运行脚本.对"日常问题"感到抱歉.请帮忙!

<?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 * FROM 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'); …
Run Code Online (Sandbox Code Playgroud)

php mysql smarty3

6
推荐指数
3
解决办法
954
查看次数

标签 统计

mysql ×1

php ×1

smarty3 ×1