SoFunction
Updated on 2025-04-04

Example analysis of Yii data reading and jump parameter transfer usage

This article describes the usage of Yii data reading and jump parameter transfer. Share it for your reference, as follows:

$toop=array('id'=>'aaaa','name'=>'bbbb','nickname'=>'ccccc','phone'=>'ddddd','status'=>'eeeeee','mytest'=>$te);
$test='hello world!';
$te="\$this->test='qweqw'";
$conn=Yii::app()->db;
$sql="select * from tbl_user";
$command=$conn->createCommand($sql);
$dataReader=$command->query();
//$rows=$dataReader->readAll();
while(($row=$dataReader->read())!==false) {
  var_dump($row);
}
$this->render('index',array('toop'=>$toop,'var1'=>$test,'var2'=>$te));

The result of $row is:

array (size=4)
 'id' => string '1' (length=1)
 'username' => string 'test1' (length=5)
 'password' => string 'pass1' (length=5)
 'email' => string 'test1@' (length=17)
array (size=4)
 'id' => string '2' (length=1)
 'username' => string 'test2' (length=5)
 'password' => string 'pass2' (length=5)
 'email' => string 'test2@' (length=17)
array (size=4)
 'id' => string '3' (length=1)
 'username' => string 'test3' (length=5)
 'password' => string 'pass3' (length=5)
 'email' => string 'test3@' (length=17)

Results of $rows:

array (size=21)
 0 =>
  array (size=4)
   'id' => string '1' (length=1)
   'username' => string 'test1' (length=5)
   'password' => string 'pass1' (length=5)
   'email' => string 'test1@' (length=17)
 1 =>
  array (size=4)
   'id' => string '2' (length=1)
   'username' => string 'test2' (length=5)
   'password' => string 'pass2' (length=5)
   'email' => string 'test2@' (length=17)
 2 =>
  array (size=4)
   'id' => string '3' (length=1)
   'username' => string 'test3' (length=5)
   'password' => string 'pass3' (length=5)
   'email' => string 'test3@' (length=17)
 3 =>
  array (size=4)
   'id' => string '4' (length=1)
   'username' => string 'test4' (length=5)
   'password' => string 'pass4' (length=5)
   'email' => string 'test4@' (length=17)

$dataReader->read() and $dataReader->readAll() cannot be used at the same time. After $dataReader->read() is read, the read by $dataReader->readAll() is empty, otherwise.

The parameters passed through render can be called like this:

<?php
var_dump($toop);
var_dump($var1);
var_dump($var2);
?>

For more information about Yii, readers who are interested in this site can view the topic:Yii framework introduction and common techniques summary》、《Summary of excellent development framework for php》、《Basic tutorial on getting started with smarty templates》、《Summary of the usage of php date and time》、《PHP object-oriented programming tutorial》、《Summary of usage of php strings》、《PHP+mysql database operation tutorial"and"Summary of common database operation techniques for php

I hope that this article will be helpful to everyone's PHP programming based on the Yii framework.