如何从PHP访问数据库? [英] How can I access to database from PHP?
本文介绍了如何从PHP访问数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我试图从php访问数据库,但经过一些尝试后我无法支付
这是代码< br $>
$ mysqli = new mysqli( ipAddress(hostname), UserName, 密码, DbName);
if($ mysqli-> connect_error)
die(' 连接错误(' .mysqli_connect_errno()。' )' .mysqli_connect_error());
else echo 成功;
也是这个
$ dbhandle = mysql_connect( ipAddress(hostname), UserName , 密码)
或 die( 无法连接到MySQL);
// echo连接到MySQL< br>;
// 选择要使用的数据库
$ selected = mysql_select_db( DbName,$ dbhandle)
或 die( 无法选择数据库);
给我错误消息
访问被拒绝用户'UserName'@'ipAddress'(使用密码:YES)在../client.php
但是当我使用C#
没有错误消息
string query = string .Format( 从information_schema.tables中选择{0}, table_name);
MySqlDataAdapter DA = new MySqlDataAdapter(query, Server = ipAddress; User Id = userName; Password = Password; Database = DbName);
DataSet Ds = new DataSet();
DA.Fill(Ds, 表);
plz帮帮我
我试过的:
我试图在php中使用许多不同的代码,但我无法访问数据库
解决方案
mysqli = new mysqli( ipAddress(hostname), UserName, 密码, DBNAME跨度>);
if(
mysqli-> connect_error)
die(' 连接错误(' .mysqli_connect_errno()。' )' .mysqli_connect_error());
else echo 成功;
也是这个
dbhandle = mysql_connect( ipAddress(hostname), UserName, 密码)
或 die( 无法连接到MySQL);
// echo连接到MySQL< br>;
// 选择要使用的数据库
Hi Everyone
I tried to access to database from php but i couldn't after some attempts
this is the code
$mysqli = new mysqli("ipAddress(hostname)", "UserName", "Password", "DbName");
if($mysqli->connect_error)
die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());
else echo "Success";
also this
$dbhandle = mysql_connect("ipAddress(hostname)", "UserName", "Password")
or die("Unable to connect to MySQL");
//echo "Connected to MySQL<br>";
//select a database to work with
$selected = mysql_select_db("DbName",$dbhandle)
or die("Could not select Database");
give me error messsage
Access denied for user 'UserName'@'ipAddress' (using password: YES) in ../client.php
but when I use C#
No Error Message
string query = string.Format("Select {0} from information_schema.tables ", "table_name");
MySqlDataAdapter DA = new MySqlDataAdapter(query,"Server=ipAddress;User Id=userName;Password=Password;Database=DbName");
DataSet Ds = new DataSet();
DA.Fill(Ds, "Tables");
plz help me
What I have tried:
I tried to use many different codes in php but i couldn't to access database
解决方案
mysqli = new mysqli("ipAddress(hostname)", "UserName", "Password", "DbName"); if(
mysqli->connect_error) die('Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error()); else echo "Success";
also this
dbhandle = mysql_connect("ipAddress(hostname)", "UserName", "Password") or die("Unable to connect to MySQL"); //echo "Connected to MySQL<br>"; //select a database to work with
这篇关于如何从PHP访问数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文