我可以在 PHP 中混合 MySQL API 吗? [英] Can I mix MySQL APIs in PHP?

查看:23
本文介绍了我可以在 PHP 中混合 MySQL API 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索过,目前我看到的是你可以将mysql_mysqli_一起使用,意思是:

I have searched the net and so far what I have seen is that you can use mysql_ and mysqli_ together meaning:

<?php
$con=mysqli_connect("localhost", "root" ,"" ,"mysql");

if( mysqli_connect_errno( $con ) ) {
    echo "failed to connect";
}else{
    echo "connected";
}
mysql_close($con);
echo "Done";
?>

<?php
$con=mysql_connect("localhost", "root" ,"" ,"mysql");
if( mysqli_connect_errno( $con ) ) {
    echo "failed to connect";
}else{
    echo "connected";
}
mysqli_close($con);
echo "Done";
?>

有效,但当我使用此代码时,我得到的是:

Are valid but when I use this code what I get is:

Connected
Warning: mysql_close() expects parameter 1 to be resource, object given in D:\************.php on line 9
Done

对于第一个和除了 mysqli_close() 之外的相同.对于第二个.

For the first and the same except with mysqli_close(). For the second one.

有什么问题?我不能一起使用mysql_mysqli 吗?还是正常的?我可以检查连接是否有效的方法吗?(if(mysq...))

What is the problem? Can't I use mysql_ and mysqli together? Or is it normal? Is the way I can check if the connections are valid at all? (the if(mysq...))

推荐答案

不,你不能同时使用 mysqlmysqli.它们是独立的 API,它们创建的资源彼此不兼容.

No, you can't use mysql and mysqli together. They are separate APIs and the resources they create are incompatible with one another.

不过有一个 mysqli_close.

这篇关于我可以在 PHP 中混合 MySQL API 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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