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

查看:50
本文介绍了我可以在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天全站免登陆