![](/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.