$pdo=new PDO("mysql:host=localhost;dbname=t1","root","");
$sth=$pdo->query('select * from blog');
$result = $sth->fetchALL(PDO::FETCH_ASSOC);
foreach($result as $v){
print_r($v);
}
?>
回复讨论(解决方案)
用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
$rows[] = $row;//将每次查的结果装到之前定义的数组
}
$pdo=new PDO("mysql:host=localhost;dbname=mysql","root","");$sth=$pdo->query('select * from user');$result = $sth->fetchALL(PDO::FETCH_ASSOC);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '<pre class="brush:php;toolbar:false">';print_r($tmp_ary);echo '';
用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
$rows[] = $row;//将每次查的结果装到之前定义的数组
}
提示错误 是怎么回事?
Fatal error: Call to a member function fetch_row() on a non-object in D:\wamp\www\cxblog2.php on line 9
$pdo=new PDO("mysql:host=localhost;dbname=mysql","root","");$sth=$pdo->query('select * from user');$result = $sth->fetchALL(PDO::FETCH_ASSOC);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '<pre class="brush:php;toolbar:false">';print_r($tmp_ary);echo '';
这打印出来的还是一个数组啊
$pdo=new PDO("mysql:host=localhost;dbname=mysql","root","");$sth=$pdo->query('select * from user');$result = $sth->fetchALL(PDO::FETCH_ASSOC);$tmp_ary=array();foreach($result as $v){ $tmp_ary[]=array_values($v);}echo '<pre class="brush:php;toolbar:false">';print_r($tmp_ary);echo '';
这样打印出来还是有键名啊
参数 PDO::FETCH_ASSOC 返回关联键数组,键名为列名
参数 PDO::FETCH_NUM 返回下标数组,下标从 0 开始
fetch 和 fetchALL 总是返回数组,因为 php 不能预知查询结果有几列(不对 sql 指令做语法分析)
用fetch_row(),重新建建一个数组,将查到的内容装到新数组里,这样就没原来的键值名了
$rows = array();//建立一个数组用来装查询结果
while($row = $result->fetch_row()){//只要能查到结果就执行
$rows[] = $row;//将每次查的结果装到之前定义的数组
}
提示错误 是怎么回事?
Fatal error: Call to a member function fetch_row() on a non-object in D:\wamp\www\cxblog2.php on line 9
你的sql查询语句是什么,可能你查出来的$result不是一个对象

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools