用php连接到mysql [英] Connecting to mysql with php

查看:64
本文介绍了用php连接到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我一直绞尽脑汁试图找出我所缺少的东西

跟随这本书获取一个php脚本工作。如果有人能指出我的错误,我真的很感激

。我的所有配置文件已经很晚了。

。为什么他们总是为

应用程序安装scim并将其放在附录中,这是新用户需要做的第一件事。然后我们遇到了这些问题,因为作者认为这是理所当然的




谢谢


Howard


我正在使用Apache 2.0.55和PHP 5.1.2以及MySql AB 5.0.18。 Windows XP SP2。


我相信我缺少的是如何告诉PHP&数据库

的Apache是​​什么?


这是我安装的路径。

C:/ mysql / bin, c:/ mysql / data / books,c:/ apached / apache2 / htdocs用于服务器

up网页,c:/ php。


这里是apache中的错误日志,以及脚本


[2006年2月14日03:31:27] [错误] [客户端127.0.0.1] PHP解析错误:

语法错误,意外的T_STRING在/ b
C:\\Apache \\Apache2 \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ /> http://127.0.0.1/search.html


这是脚本。第30行是$ result = mysql_query如果你是
从1开始计数或者$ query = select如果第一行是0.

<?php


包括config.php;

包括opendb.php;


//创建短变量名
< br $>
$ searchtype = $ _ POST [''searchtype''];

$ searchterm = $ _ POST [''searchterm''];

$ searchterm = trim($ searchterm);


if(!$ searchtype ||!$ searchterm)


{

echo''您尚未输入搜索详细信息。请回去再试一次。'';

退出;

}


mysql_select_db(''books'');

$ searchtype = addslashes($ searchtype);

$ searchterm = addslashes($ searchterm);


$ query = select *来自书籍。$ searchtype。比如''%'。$ searchterm。"%''

" ;

$ result = mysql_query($ query);


$ num_results = mysql_num_rows($ result);


echo''< p>找到的书籍数量:''。$ num_results。''< / p>'';


for($ i = 0; $ i < $ num_results; $ i ++)

{

$ row = mysql_fetch_array($ result);

echo''< p>< ;强> '' '($ I + 1)。'。标题:'';

echo htmlspecialchars(stripslashes($ row [''title'']));

echo''< / strong>< br / >作者:'';

echo stripslashes($ row [''author'']);

echo''< br /> ISBN:'' ;

echo stripslashes($ row [''isbn'']);

echo''< br />价格:'';

echo stripslashes($ row [''price'']);

echo''< / p>'';

}

?>

解决方案

result = mysql_query如果你

从1开始计数或


query =选择第一行是否为0.

<?php


包括config.php;

包括opendb.php;


//创建短变量名


searchtype =

Hi,

I have been racking my brain trying to figure out what I am missing trying
to follow this book to get a php script to work. I would really appreciate
if someone could point out my errors. I''ve been up really late going over
all the config files. Why do they always scim installation for the
applications and put it in the Appendix when its the first thing that new
users need to do. Then we run into these problems because the author takes
so much for granted

Thanks

Howard

I''m using Apache 2.0.55 with PHP 5.1.2 and MySql AB 5.0.18. Windows XP SP2.

What I believe I''m missing is how do I tell PHP & Apache where the Databases
are??

Here is the pathing my my installs.
C:/mysql/bin, c:/mysql/data/books, c:/apached/apache2/htdocs for servering
up web pages, and c:/php.

Here is the error log in apache, and the script

[Tue Feb 14 03:31:27 2006] [error] [client 127.0.0.1] PHP Parse error:
syntax error, unexpected T_STRING in
C:\\Apache\\Apache2\\htdocs\\results.php on line 30, referer:
http://127.0.0.1/search.html

And here is the script. The line 30 is the $result = mysql_query if you
count starting with 1 or $query = select if the first line is 0.
<?php

include config.php;
include opendb.php;

// create short variable names

$searchtype=$_POST[''searchtype''];
$searchterm=$_POST[''searchterm''];
$searchterm= trim($searchterm);

if (!$searchtype || !$searchterm)

{
echo ''You have not entered search details. Please go back and try again.'';
exit;
}

mysql_select_db(''books'');
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);

$query = select * from books where ".$searchtype." like ''%".$searchterm."%''
" ;
$result = mysql_query($query);

$num_results = mysql_num_rows($result);

echo ''<p>Number of books found: ''.$num_results.''</p>'';

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo ''<p><strong>''.($i+1).''. Title: '';
echo htmlspecialchars(stripslashes($row[''title'']));
echo ''</strong><br />Author: '';
echo stripslashes($row[''author'']);
echo ''<br />ISBN: '';
echo stripslashes($row[''isbn'']);
echo ''<br />Price: '';
echo stripslashes($row[''price'']);
echo ''</p>'';
}
?>

解决方案

result = mysql_query if you
count starting with 1 or


query = select if the first line is 0.
<?php

include config.php;
include opendb.php;

// create short variable names


searchtype=


这篇关于用php连接到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆