Привет, я пытаюсь вставить URL-адрес и его содержимое в 2 таблицы, но я буду использовать идентификатор из таблицы и вставлять этот идентификатор в несколько записей во второй таблице. Надеюсь, мне удастся прояснить мою проблему здесь, проблема, которую я могу просматривать данные, но я не могу вставить данные в mysql с помощью pdo, все, что я получил в mysql, это значения NULL, это мой код для более ясного понимания
сначала мой файл класса похож на эти ссылки. php
/**
* Sets the object's properties using the values in the supplied array
*
* @param assoc The property values
*/
public function __construct1( $data=array() ) {
if ( isset( $data['listURL'] ) ) $this->listURL = $data['listURL'];
if ( isset( $data['hostname'] ) ) $this->hstname = $data['hostname'];
}
/**
* Sets the object's properties using the values in the supplied array
*
* @param assoc The property values
*/
public function __construct2( $data=array() ) {
if ( isset( $data['stringName'] ) ) $this->stringName = $data['stringName'];
if ( isset( $data['stringUrl'] ) ) $this->stringUrl = $stringUrl = $data['stringUrl'];
}
/**
* Sets the object's properties using the edit form post values in the supplied array
*
* @param assoc The form post values
*/
public function storeFormValues1 ( $params ) {
// Store all the parameters
$this->__construct1( $params );
}
/**
* Sets the object's properties using the edit form post values in the supplied array
*
* @param assoc The form post values
*/
public function storeFormValues2 ( $params ) {
// Store all the parameters
$this->__construct2( $params );
}
public function insertlistFuncClass() {
$conn = new PDO(DB_NDS, DB_USERNAME, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$sql = "INSERT INTO lists ( listURL, hostname ) VALUES (:listURL, :hostname)";
$st = $conn->prepare($sql);
$st->bindValue( ":listurl", $this->url, PDO::PARAM_STR );
$st->bindValue( ":hostname", $this->hstname, PDO::PARAM_STR );
$st->execute();
$listId = $conn->lastInsertId();
$conn = null;
}
public function insertStringsFuncClass() {
$listId = $this->listId;
$conn = new PDO(DB_NDS, DB_USERNAME, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$sql = "INSERT INTO Strngs ( stringName, stringUrl, listId ) VALUES (:stringName, :stringUrl, :listId)";
$st = $conn->prepare($sql);
$st->bindValue( ":stringName", $this->channelName, PDO::PARAM_STR );
$st->bindValue( ":stringUrl", $this->streamUrl, PDO::PARAM_STR );
$st->bindValue( ":listId", $listId, PDO::PARAM_STR );
$st->execute();
$conn = null;
}
для файла. php это так:
require("config.php");
session_start();
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
function insertlists()
{
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('allow-origin: *');
header("Access-Control-Allow-Headers: ACCEPT, CONTENT-TYPE, X-CSRF-TOKEN");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE");
$url = $_POST['url'];
print $url . " was successfully submitted ";
$createdate = date('Y/m/d H:i:s');
$hstname = parse_url($url, PHP_URL_HOST);
$listsInfo = array();
$listArr = array(
'listURL' => $url,
'hostname' => $hstname
);
$listInfo[] = $playlistArr;
print_r($playlistArr);
$mylink = new Lists;
$mylink->storeFormValues1($_POST);
$mylink->insertPlaylistFuncClass();
}
function insertStrings()
{
insertlists();
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('allow-origin: *');
header("Access-Control-Allow-Headers: ACCEPT, CONTENT-TYPE, X-CSRF-TOKEN");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, DELETE");
$m3ufile = file_get_contents($url);
$find = ['/((?:https?|rtmp):\/\/(?:\S*?\.\S*?)(?:[\s)\[\]{};"\'<]?(.mp4)|\.\s|$))/', '/((?:https?|rtmp):\/\/(?:\S*?\.\S*?)(?:[\s)\[\]{};"\'<]?(.avi)|\.\s|$))/', '/((?:https?|rtmp):\/\/(?:\S*?\.\S*?)(?:[\s)\[\]{};"\'<]?(.mkv)|\.\s|$))/'];
$replace = ['', '', ''];
$result = preg_replace($find, $replace, $m3ufile);
$re = '/((?:https?|rtmp):\/\/(?:\S*?\.\S*?)(?:[\s)\[\]{};"\'<]|\.\s|$))/';
$attributes = '/([a-zA-Z0-9\-\_]+?)="([^"]*)"/';
preg_match_all($re, $result, $matches);
$items = array();
foreach ($matches[0] as $list) {
preg_match($re, $list, $matchList);
$mediaURL = preg_replace("/[\n\r]/", "", $matchList[3]);
$mediaURL = preg_replace('/\s+/', '', $mediaURL);
$channelName = $matchList[2];
$stringUrl = $mediaURL;
$newdata = array(
'stringName' => $matchList[2],
'listURL' => $url,
'stringUrl' => $mediaURL,
'listId' => ':listId'
);
preg_match_all($attributes, $list, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
$newdata[$match[1]] = $match[2];
}
$items[] = $newdata;
echo 'Insert: (' . $matchList[2] . ' - ' . $mediaURL . ' - ' . $url . ')' . "\r\n";
$mylink = new Article;
$mylink->storeFormValues2($_POST);
$mylink->insertstringsFuncClass();
}
}
insertStrings();
все, что я получил для вставленных значений, равно null