php - 将 PHP 连接到 SQL 女士
问题描述
我已经完成了在 PHP 和 Ms SQL 之间建立连接的所有步骤,但它仍然无法正常工作并显示错误“致命错误:未捕获的错误:调用未定义的函数 sqlsrv_connect()”。我也安装了 MS SQL 驱动程序。我在 php.ini 中使用的扩展现在是 php_pdo_sqlsrv_53_ts_vc9.dll,但它不包含在 xampp 扩展中。TCP/IP 也已启用。
解决方案
您可以使用 PDO 语句连接下面的示例:
# Connecting to PostGreSQL
$dbh = new PDO("msql:dbname=$dbname; host=$host", $username, $password);
# Setting an attribute on the database handle and error reporting
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
# Prepares a statement for execution and returns a statement object
$query = 'SELECT * FROM test';
$stmt = $dbh->prepare($query);
$stmt->execute();
# Set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
# Returns an array containing all the results from the query
$allRows = $stmt->fetchAll();
推荐阅读
- web - 为什么在 homeurl.com/landing 页面上有一个域landingpage.homeurl.com?
- python - 时间数据 mm/dd/YYYY 与指定的格式不匹配
- angular - agm-map' 不是已知元素
- eclipse - 为什么在脏编辑器关闭或不保存时出现堆栈溢出错误?
- linux - 尝试制作文件时出现错误 1(mips、程序集)
- javascript - 如何正确获取活动类的索引号
- python - 如何使用 Elasticsearch 在日期范围内使用 id 条件获取值的总和?
- tmux - Tmux 无法识别元键映射
- sql-server - SQL Server Bad query performance: Bad Rows Estimate, but Statistic is accurate?
- android - E/paypal.sdk: INTERNAL_SERVER_ERROR -PayPal Integration (Android)