我最近对我为我工作的公司建立的一个网站进行了大修。因为我在一年前就开始了这个项目,我的编码技巧有了很大的提高,我想让这个网站跟上速度。我对这个项目的主要关注是安全性和速度。我一直在做的一件事是更改我的所有PHP连接,以确保它们是安全和快速的。这是我从数据库中提取内容时通常遵循的格式:
<?php
//Connect to MySQL
require_once('includes/config.php');
$link = mysql_connect($host, $user, $pass);
if(!$link) {
d
我目前有一个带有html代码的php文件。在主体标记im的开头,包括包含db连接的dbcon.php、查询和fetch_result。我现在想在html文件后面使用这些结果,但是我无法让它工作。
网站-档案如下:
<html>
<head>...</head>
<body>
<?php include("dbcon.php"); ?>
...
<some html stuff>
...
<? here i want to use the data from the query ?>
...
&l
基本上,我一直在尝试创建一个配置文件,所以当我完成我当前的网站时,编辑MYSQL到在线数据库的连接信息要容易得多。我拥有的连接代码在需要时在每个文件中都能很好地工作,但当我尝试在配置文件中的相同代码上使用一次required时,它显示没有选择数据库。当连接代码预先写入到文件中时,不会发生此错误。这是我的配置文件代码,然后是已经在工作页面上的工作代码。
配置php
<?php
//configures connection to the mysql database.
$con = mysql_connect("localhost","james");
if
我在网站中使用PDO,现在我需要一个使用mysql_xxx函数的php类。它不连接并选择db本身,您应该这样使用它:
if (!($connection = @mysql_connect($MySQL_host, $MySQL_user, $MySQL_pass))) {
die('Error connecting to the database!'); }
if (!@mysql_select_db($MySQL_database, $connection)) {
die('Error selecting
请帮个忙。“我的网站”未与数据库连接。
下面是我的代码:
<?php
$serverName="localhost";
$dbusername="root";
$dbpassword="";
$dbname="bank_db";
mysql_connect($serverName,$dbusername,$dbpassword)/* or die('the website
is down for maintainance')*/;
mysql_select_db($dbname) or die(mysql_