![](/img/trans.png)
[英]select matching data in mysql table by setting mysql session variable?
[英]Setting a mysql table in a variable
好的,所以我正在使用以下代碼將表存儲在變量中:
<?php
$host = "localhost";
$user = "x";
$password = "x";
try {
$account = new PDO("mysql:host=$host;dbname=account", $user, $password);
} catch(PDOException $e) {
die('connection cant be made');
}
try {
$player = new PDO("mysql:host=$host;dbname=player", $user, $password);
} catch(PDOException $e) {
die('connection cant be made');
}
我得到的所有信息都是“無法建立連接”。 因此,我找到了另一個代碼,然后切換到該代碼,一切正常。
<?php
$host = "localhost"; // Ip-ul de la server
$user= "xx"; // User-ul de conectare la database
$password = "xx"; // Parola de conectare la database
mysql_connect($server, $user, $password) or die(mysql_error());
mysql_select_db('account');
mysql_set_charset('utf8');
?>但現在我沒有為$ account和$ player分配任何數據庫,因此我無法正常使用我的網站。 有想法嗎?
在$e
您有理由無法連接數據庫。 捕獲異常,不執行任何操作...
<?php
define('__DEBUG', true);
try {
$account = new PDO("mysql:host=$host;dbname=account", $user, $password);
} catch(PDOException $e) {
if(__DEBUG) {
print $e->getMessage();
}
die('connection cant be made');
}
使用2種連接方式(不是so ^)的舊樣式:
$con1 = mysqli_connect();
$con2 = mysqli_connect();
mysqli_query('query', $con1);
mysqli_query('query', $con2);
^使用mysqli_
代替mysql_
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.