数据库相关问题
数据库相关问题
这节将讨论PHP和数据库之间最普通的问题。夸张地说,PHP几乎可以操作今天市面上有的所有的数据库。
1. 我听说PHP可以操作微软的SQL Server.应该怎样做?
2. 我可以操作微软 Access 数据库吗?
3. 我升级到了PHP 4, 现在我的mysql总是告诉我: "Warning: MySQL: Unable to save result set in ...". 这是怎么回事?
4. 安装完共享mysql支持后, 一装入libphp4.so Apache 就 dumps core . 这个问题可以修复吗?
5. 为什么我总得到这样的错误消息: : "Warning: 0 is not a MySQL result index in
1. 我听说PHP可以操作微软的SQL Server.应该怎样做?
在Windows平台下, 你只要使用包里所含的ODBC驱动程序就可以了。
在Unix平台下, 你可以使用Sybase-CT driver 来操作 Microsoft SQL Servers。因为它们的协议(至少绝大部份的产品) 是完全兼容的. Sybase 有一个免费的 Linux systems 版本. 对另外一些的Unix系统来说,你可能需要联系 Sybase,以得到正确的库文件 . 也可以参照下面一些问题的答案。
2. 我可以操作 Microsoft Access数据库吗?
是的。如果你是在 Windows 9x/Me, 或 NT/2000下运行,你已经有了所有必须的工具。 你可以使用ODBC 和 Microsoft's ODBC drivers for Microsoft Access databases。
如果你是在 Unix 下运行PHP,想要和Windows下的 MS Access 通讯,那么你需要Unix ODBC drivers. OpenLink Software 提供了一个 Unix-based ODBC drivers。 你可以下载一个试用(不过期)的 pilot 程序, 商业版本的价格定位在 $675
另外一种办法是使用带 Windows ODBC驱动的 SQL server来存诸数据,然后你可以用Microsoft Access (ODBC) and PHP (内置SQL Server驱动)来操作这个库。或者使用另一种文件格式, Access 和 PHP 都可以打开的, 比如操作系统文件或dBase 数据库等。关于这 OpenLink software的Tim Hayes 写了如下的文字: 在你可以使用PHP直接操作一种数据库里,使用另外的库作为中间件不是一个好的主意。
--例如用OpenLink's 驱动. 如果你确实需要中间件库, OpenLink 现在发布了 Virtuoso (虚拟数据库引擎), 可以运行在NT, Linux 其它的 unix平台.
请参阅 website 免费下载.
另一个成功的范例子是使用Windows下的Mysql(通过mysql ODBC),来同步化 Access 数据库. Steve Lawrence 写到:
按照Mysql的指引安装你的平台下的Mysql. 最新版本可以从 http://www.mysql.com/ 得到(从你最近的镜像点!). 除了设置一个Mysql的数据库,不需要其它特别的配置, 设置用户帐号, 你应该把用户的主机域 设为“%”, 确认你的服务器名、数据库名等
在Mysql的站点上下找Mysql ODBC驱动,最新的版本应该是 myodbc-2_50_19-win95.zip (NT)。在你的Windows下安装它. 你可以用工具包里的工具测试安装是否成功。
在你的 ODBC 管理器(控制面板里)里创建一个用户和系统的dsn。建一个DSN名, 输入你的主机名, 用户名(mysql), 口令,端口号, 等你在第一步里设置的数据。
完全安装Access, 这一步使你安装必须的工具驱动.. 至少 你需要管理连接的数据库表。
现在最有趣的事发生了! 建一个新的Access数据库。 在表里右键,选"link Tables"(链接表), 或者在 “文件” 菜单 下, 选“ Get External Data ”(获取外部数据) 然后“ Link Tables”(链接表). 当对话框打开时,选择文件类型: ODBC. 选择系统DSN,你在第三步创建的DSN名. 然后选要链接的表。按“确定”, 哦! 你现在可以在你的Mysql管理器上打开这个表, 可以增加/编辑/删除 数据! 你也可以建立查询, 输入/输出表到 MySQL, 建立表单及报表,等.
Tips and Tricks:
你可以建立Access表,把它输出到 MySQL, 也可以链接回来. 它会使创建表快些.
当你在Access里创建表时, 必须设置主键。 同样,在Mysql里连到access时,也要有主键。
如果你在 MySQL时选了一张表, 你不得不在Access里重新链接.去>add-ins>链接表管理器
3. 我升级到了PHP 4, 现在我的mysql总是告诉我: "Warning: MySQL: Unable to save result set in ...". 这是怎么回事?
大部分这样的问题,是因为 PHP 4 编译选项 '--with-mysql'没有标明你的Mysql的路径。 这样PHP就会使用它内建的MySQL库. 如果你的系统运行在这样的平台下, PHP 3 作为 Apache 模块, 或者 auth-mysql, 它们使用另外版本的Mysql驱动,这样在两个不同版本的Mysql客户端驱动上就会存在冲突。
重新编译PHP 4, 增加Mysql的路径信息, '--with-mysql=/your/path/to/mysql' 通常都能解决这个问题。
4. 安装完共享mysql支持后, 一装入libphp4.so Apache 就 dumps core . 这个问题可以修复吗?
如果你的Mysql是用 pthreads 连接的,将会发生这种情况。请使用 ldd。 如果已使用, grab the MySQL tarball and 重新编译, 或 从源代码rpm编译,移去相关文件里的打开 threaded client 代码的开关 。如果以上的两种方法都不能修复这个错误,那么重新编译新的PHP库支持新的Mysql。
5. 为什么我总得到这样的错误消息: : "Warning: 0 is not a MySQL result index in on line " or "Warning: Supplied argument is not a valid MySQL result resource in on line ?
你正在使用的结果集变量值是0。0意味着 因为某种原因你的查询失败了。在你取得结果集之前,你必须检查提交查询失败的原因。正确的写法应该如下: $result = mysql_query("SELECT * FROM tables_priv");
if (!$result) {
echo mysql_error();
exit;
}
or $result = mysql_query("SELECT * FROM tables_priv")
or die("Bad query: ".mysql_error());

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.
