2012-11-30 21 views
0

经过几周的时间,使用参考书籍将网站放在一起后,现在发现mysql是多余的,而且我需要将所有内容都更改为mysqli,但是我对于如何完全做到这一点甚至得到严重冲突的结果尽管这意味着需要几分钟的时间。mysqli migration

任何人都可以告诉我现有的代码有什么问题 - 至少可以说 - 这很难变成mysql,因为每次尝试新解决方案时,我都会得到一个完全空白的页面。

顺便说一句,目前的一切工作很好。

这里的配置页面我连接到:

<?php 
# FileName="Connection_php_mysqli.htm" 
# Type="MYSQL" 
# HTTP="true" 
$hostname_em = "localhost"; 
$database_em = "php_test"; 
$username_em = "username"; 
$password_em = "password"; 
$em = mysql_pconnect($hostname_em, $username_em, $password_em) or trigger_error(mysql_error(),E_USER_ERROR); 
?> 

这里是我的头:

<?php require_once('connections/em.php'); ?> 
<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
if (PHP_VERSION < 6) { 
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
} 

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

switch ($theType) { 
case "text": 
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
    break;  
case "long": 
case "int": 
    $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
    break; 
case "double": 
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
    break; 
case "date": 
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
    break; 
case "defined": 
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
    break; 
} 
return $theValue; 
} 
} 

//Query for tblReviews 
mysql_select_db($database_em, $em); 
$query_getReview = "SELECT reviews.title, reviews.cover_art, reviews.blog_entry, reviews.rating, reviews.published, reviews.updated, artists.artists_name, contributors.contributors_name, contributors.contributors_photo, contributors.contributors_popup, categories_name FROM reviews JOIN artists ON artists.id = reviews.artistid JOIN contributors ON contributors.id = reviews.contributorid JOIN categories ON categories.id = reviews.categoryid ORDER BY reviews.updated DESC LIMIT 3"; 
$getReview = mysql_query($query_getReview, $em) or die(mysql_error()); 
$row_getReview = mysql_fetch_assoc($getReview); 
$totalRows_getReview = mysql_num_rows($getReview); 

mysql_select_db($database_em, $em); 
$query_getFeature = "SELECT features.features_words, features.published, features.updated, artists.artists_name, contributors.contributors_name, contributors.contributors_photo, contributors.contributors_popup, categories_name 
FROM features JOIN artists ON artists.id = features.artistid JOIN contributors ON contributors.id = features.contributorid JOIN categories ON categories.id = features.categoryid ORDER BY features.updated DESC LIMIT 1"; 
$getFeature= mysql_query($query_getFeature, $em) or die(mysql_error()); 
$row_getFeature = mysql_fetch_assoc($getFeature); 
$totalRows_getFeature = mysql_num_rows($getFeature); 
?> 

最后的地方,它的所有显示器(我要包括所有的情况下,这是一个当我尝试执行迁移时,会发生以下事情):

<?php do { ?> 
<table id="center_table" width="650" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
    <td width="650" height="30" colspan="3" bgcolor="#FFFFFF"><a class="category" href="/" target="_top"><?php echo $row_getReview['categories_name']; ?></span></td><!-- category --> 
</tr> 
<tr> 
    <td width="60" height="60" rowspan="2" bgcolor="#FFFFFF"><span class="product_photo"><a href="<?php echo $row_getReview['cover_art']; ?>"><img id="product_photo" src="images/covers/<?php echo $row_getReview['cover_art']; ?>" width="60" height="60" border="0" alt="product_image" /></a><span></td><!-- product photo --> 
    <td width="590" height="30" colspan="2" bgcolor="#FFFFFF"><span class="artist"><?php echo $row_getReview['artists_name']; ?></span><span class="title"><?php echo $row_getReview['title']; ?></td><!-- artist & title --> 
</tr> 
<tr> 
    <td width="35" height="25" bgcolor="#FFFFFF"><div class="ienlarger"><img id="contributor_photo" /><a href="<?php echo $row_getReview['contributors_website']; ?>"><img src="<?php echo $row_getReview['contributors_photo']; ?>" alt="thumb" class="resize_thumb" /><span><img src="<?php echo $row_getReview['contributors_popup']; ?>" alt="large" /></span></a></div></td><!-- contributor photo --> 
    <td width="555" height="25" bgcolor="#FFFFFF"><span class="contributor">Written by</span>&nbsp;<?php echo $row_getReview['contributors_name']; ?></td><!-- Written by Contributor Name --> 
</tr> 
<tr> 
    <td width="650" colspan="3" bgcolor="#FFFFFF" valign="top"><p class="blog_entry"><?php echo nl2br($row_getReview['blog_entry']); ?></p></td><!-- Review --> 
</tr> 
<tr> 
    <td width="650" height="15" colspan="3" bgcolor="#FFFFFF"><!-- rating --> 
     <span class="rating">Rating :</span>&nbsp;<?php echo $row_getReview['rating']; ?>&nbsp;(out of a possible 1,000,000)<span class="published">Published :</span>&nbsp;<?php echo $row_getReview['published']; ?><span class="published">Updated :</span>&nbsp;<?php echo $row_getReview['updated']; ?></td> 
</tr> 
<tr> 
    <td width="650" height="15" colspan="3" bgcolor="#FFFFFF"> 
     <img src="images/spacer.gif" width="650" height="15" alt="" /></td> 
</tr> 
</table> 
<?php } while ($row_getReview = mysql_fetch_assoc($getReview)); ?> 
<?php do { ?> 
<table id="center_table" width="650" border="0" cellpadding="0" cellspacing="0"> 
<tr> 
    <td width="650" height="30" colspan="3" bgcolor="#FFFFFF"><a class="category" href="/" target="_top"><?php echo $row_getFeature['categories_name']; ?</span></td><!-- category --> 
</tr> 
<tr> 
    <td width="60" height="60" rowspan="2" bgcolor="#FFFFFF">&nbsp;</td><!-- product photo --> 
    <td width="590" height="30" colspan="2" bgcolor="#FFFFFF"><span class="artist"><?php echo $row_getFeature['artists_name']; ?></span><span class="title">Interview</td><!-- artist & title --> 
</tr> 
<tr> 
    <td width="35" height="25" bgcolor="#FFFFFF"><div class="ienlarger"><img id="contributor_photo" /><a href="<?php echo $row_getFeature['contributors_website']; ?>"><img src="<?php echo $row_getFeature['contributors_photo']; ?>" alt="thumb" class="resize_thumb" /><span><img src="<?php echo $row_getFeature['contributors_popup']; ?>" alt="large" /></span></a></div></td><!-- contributor photo --> 
    <td width="555" height="25" bgcolor="#FFFFFF"><span class="contributor">Written by</span>&nbsp;<?php echo $row_getFeature['contributors_name']; ?></td><!-- Written by Contributor Name --> 
</tr> 
<tr> 
    <td width="650" colspan="3" bgcolor="#FFFFFF" valign="top"><p class="blog_entry"><?php echo nl2br($row_getFeature['features_words']); ?></p></td><!-- Feature --> 
</tr> 
<tr> 
    <td width="650" height="15" colspan="3" bgcolor="#FFFFFF"><!-- rating --> 
     <span class="published">Published :</span>&nbsp;<?php echo $row_getFeature['published']; ?><span class="published">Updated :</span>&nbsp;<?php echo $row_getFeature['updated']; ?></td> 
</tr> 
<tr> 
    <td width="650" height="15" colspan="3" bgcolor="#FFFFFF"> 
     <img src="images/spacer.gif" width="650" height="15" alt="" /></td> 
</tr> 
</table> 
<?php } while ($row_getFeature = mysql_fetch_assoc($getFeature)); ?> 

就像你可以看到现在还没有太多,现在是开始使用mysqli的最佳时机。

回答

0

我个人认为你现在应该开始使用mysqli,因为mysql不再被推荐用于编写新代码(http://www.php.net/manual/en/intro.mysql.php)。

也可以参考这个主题Which is fastest in PHP- MySQL or MySQLi?,“mysqli支持底层MySQL API的更多功能,比如事务和带参数的准备查询,也可以以面向对象的方式调用mysqli函数。

+0

谢谢,我明白了这一点。 –

+0

当然,欢迎您:)另外只是fyi(我猜你知道)我注意到你使用持久连接,mysqli没有_pconnect函数,所以你必须在连接时手动预置p:到主机名(http:///php.net/manual/en/mysqli.persistconns.php) – SubRed

+0

谢谢,我会将它添加到我的chrissy列表中;-) –