1 我的电脑里面有一个数据库 文件类型(Microsoft SQL Server Query File (.sql))
2 提供数据库的人给我一个例子$countTask = array();
$sql = "SELECT * FROM ella_relations WHERE user_id = 2";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$explodeIt = explode(",", $row['relation']);
$countIt = count($explodeIt);
$countTask[$row['type']] = $countIt;
}
print_r($countTask);我想通过php读取数据库,但是不知道如何操作3 被数据库搞晕,我这个电脑里面的数据库算是本地数据库,还是什么server,需要lockhost,username,password??
4 我需要怎么做,如何连接,请前辈们帮我写的详细点 跪谢!
2 提供数据库的人给我一个例子$countTask = array();
$sql = "SELECT * FROM ella_relations WHERE user_id = 2";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$explodeIt = explode(",", $row['relation']);
$countIt = count($explodeIt);
$countTask[$row['type']] = $countIt;
}
print_r($countTask);我想通过php读取数据库,但是不知道如何操作3 被数据库搞晕,我这个电脑里面的数据库算是本地数据库,还是什么server,需要lockhost,username,password??
4 我需要怎么做,如何连接,请前辈们帮我写的详细点 跪谢!
2.这个例子是连接MySQL数据库,和上面的不对路
3.需要有这个数据库的用户名和密码才能连接到
4.连接代码和那个MySQL的代码有差别,但不大,不过前提是你要会php,否则给你你也不会用http://www.php.net/manual/en/function.mssql-connect.php
<?php
// 连接,选择数据库
//$host:mysql服务地址
//$user:mysql用户名
//$psw: mysql密码
$link = mysql_connect($host='mysql_host', $user='mysql_user', $psw='mysql_password')
or die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
//选则要执行的数据库名
mysql_select_db('my_database') or die('Could not select database');// 执行 SQL 查询
$query = 'SELECT * FROM my_table';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());// 用 HTML 显示结果
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "\t<tr>\n";
foreach ($line as $col_value) {
echo "\t\t<td>$col_value</td>\n";
}
echo "\t</tr>\n";
}
echo "</table>\n";// 释放结果集
mysql_free_result($result);// 关闭连接
mysql_close($link);
?>
是的。本地数据库
-------------------------------------------
4 我需要怎么做,如何连接,请前辈们帮我写的详细点 跪谢!
http://www.w3school.com.cn/php/php_mysql_select.asp
1.导出整个数据库 mysqldump -u 用户名 -p 数据库名 > 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc > wcnc.sql 2.导出一个表 mysqldump -u 用户名 -p 数据库名 表名> 导出的文件名 mysqldump -u wcnc -p smgp_apps_wcnc users> wcnc_users.sql 3.导出一个数据库结构 mysqldump -u wcnc -p -d --add-drop-table smgp_apps_wcnc >d:\wcnc_db.sql -d 没有数据 --add-drop-table 在每个create语句之前增加一个drop table 4.导入数据库 常用source 命令 进入mysql数据库控制台, 如mysql -u root -p mysql>use 数据库 然后使用source命令,后面参数为脚本文件(如这里用到的.sql) mysql> source d:\wcnc_db.sql?
别人给你的那个文件是导出的数据,不需要密码什么的,但你要先导入你的本地数据库才能查看